/*
 * @Description:
 * @Version: 1.0
 * @Autor: laikt
 * @Date: 2020-12-30 10:43:50
 * @LastEditors: laikt
 * @LastEditTime: 2020-12-30 15:30:32
 */
import { isArray, isString } from 'lodash'
import utils from '@/utils'

/**
 * @description 权限检查
 * @param {String|Array} value 需要的权限
 * @param {Object}} config {Boolean} all 全部匹配
 * @param {Object}} config {Boolean} not 取反
 */
export default function permission(
    value = '',
    { all = false, not = false } = {}
) {
    if (isArray(value) || isString(value)) {
        const permissions = store.state.permission.permissions
        let has = utils.helper[all ? 'allIn' : 'oneOf'](permissions, value)
        if (not) {
            has = !has
        }
        return has
    } else {
        return false
    }
}
